# class Organization < ActiveRecord::Base
#   extend OrganizationRepository
#   composed_of :rank, class_name: 'Organization::Rank', mapping: %w(rank name),
#               constructor: Proc.new { |rank| Organization::Rank.find_by_name(rank) }
#   composed_of :category, class_name: 'Organization::Category', mapping: %w(category name),
#               constructor: Proc.new { |category| Organization::Category.find_by_name(category) }
#   has_ancestry
#   has_many :position_standard_assignments
#   has_many :employee_positions, class_name: 'Employee::Position'
#   has_many :positions, through: :employee_positions

#   validates :name, :uniqueness => {:scope => [:rank, :category]}

#   def self.arrange_serializable options={}, nodes=nil
#     nodes = arrange(options) if nodes.nil?
#     nodes.map do |parent, children|
#       parent.serializable_hash.merge 'children' => arrange_serializable(options, children)
#     end
#   end
# end



class Organization
  extend OrganizationRepository
  include MongoId
  # self.site = Settings.server_address
  # self.element_name = "organ"


  class << self

    def tree
      JSON.parse(RestClient.get Settings.roster_address + "/organs/tree")
    end

    def find(id)
      JSON.parse(RestClient.get Settings.roster_address + "/organs/#{id}")
    end

    def find_parent(id)
      JSON.parse(RestClient.get Settings.roster_address + "/organs/#{id}/parent")
    end

    def position_standard_assignments(id)
      PositionStandardAssignment.where(organization_id: id)
    end

  end
end
